package com.xiuyi.pixsynergybackend.controller.picture.vo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.xiuyi.pixsynergybackend.controller.user.vo.UserVO;
import com.xiuyi.pixsynergybackend.dal.dataobject.picture.PictureDO;
import com.xiuyi.pixsynergybackend.dal.dataobject.user.UserDO;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
public class PictureVO implements Serializable {

    /**
     * id
     */
    private Long id;

    /**
     * 图片 url
     */
    private String url;

    /**
     * 图片名称
     */
    private String name;

    /**
     * 简介
     */
    private String introduction;

    /**
     * 分类
     */
    private String category;

    /**
     * 标签
     */
    private List<String> tags;

    /**
     * 图片体积
     */
    private Long picSize;

    /**
     * 图片宽度
     */
    private Integer picWidth;

    /**
     * 图片高度
     */
    private Integer picHeight;

    /**
     * 图片宽高比例
     */
    private Double picScale;

    /**
     * 图片格式
     */
    private String picFormat;

    /**
     * 创建用户 id
     */
    private Long userId;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 编辑时间
     */
    private Date editTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 创建用户信息
     */
    private UserVO user;

    private static final long serialVersionUID = 1L;


    /**
     * VO 转换 DO
     *
     * @param pictureVO 返回给前端的视图封装类
     * @return
     */
    public static PictureDO voToDO(PictureVO pictureVO) {
        if (pictureVO == null) {
            return null;
        }
        PictureDO pictureDO = new PictureDO();
        BeanUtil.copyProperties(pictureVO, pictureDO);
        // 类型不同，需要单独转换
        pictureDO.setTags(JSONUtil.toJsonStr(pictureVO.getTags()));
        return pictureDO;
    }

    /**
     * DO 转换 VO
     *
     * @param pictureDO 用于数据库查询的类
     * @return
     */
    public static PictureVO doToVO(PictureDO pictureDO) {
        if (pictureDO == null) {
            return null;
        }
        PictureVO pictureVO = new PictureVO();
        BeanUtil.copyProperties(pictureDO, pictureVO);
        // 类型不同，需要单独转换
        pictureVO.setTags(JSONUtil.toList(pictureDO.getTags(), String.class));
        return pictureVO;
    }




















}
